package com.zz.spring6.resources;

import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;

// 访问类路径下资源
public class ClassPathResourceDemo {

    public static void main(String[] args) {
        loadClassPathResourceDemo("zz.txt");
    }

    public static void loadClassPathResourceDemo(String path){
        // 创建对象
        ClassPathResource resource = new ClassPathResource(path);
        System.out.println(resource.getFilename());
        System.out.println(resource.getDescription());
        try {
            InputStream in = resource.getInputStream();
            byte[] b = new byte[1024];
            while (in.read(b)!=-1){
                System.out.println(new String(b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

}
